package other;

import javax.swing.*;
import java.awt.*;

public class HeadImage extends JPanel {
    JLabel label;

    public HeadImage(String name) {
        setLayout(null);
        char latter = Character.toUpperCase(name.charAt(0));
        label = new JLabel(String.valueOf(latter));
        label.setHorizontalAlignment(SwingConstants.CENTER);
        label.setVerticalAlignment(SwingConstants.CENTER);
        label.setForeground(Color.white);
        label.setLocation(0, 0);
        setBackground(new Color(19, 90, 201));
        add(label);
    }

    public void setName(String name) {
        char latter = Character.toUpperCase(name.charAt(0));
        label.setText(String.valueOf(latter));
    }

    public void setSize(int size) {
        super.setSize(size, size);
        label.setFont(new Font("宋体", Font.BOLD, size));
        label.setSize(size, size);

    }

    public void setBounds(int x, int y, int size) {
        setBounds(x, y, size, size);
        label.setFont(new Font("宋体", Font.BOLD, size));
        label.setSize(size, size);
    }

    @Override
    protected void paintComponent(Graphics g) {
        Graphics2D g2d = (Graphics2D) g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setColor(getBackground());
        g2d.fillOval(0, 0, getWidth(), getHeight());
    }
}
